"use strict";

$(function(){
	
	//提交表单
	$(".submit").on("click",function(){
		var title=$("#title").val().trim();
		var message=$("#message").val().trim();
		var flag=true;
		
		if(title=="" || title==null){
			Global.showTip("#title","请输入标题！");
			flag=false;
		}
		
		if(message=="" || message==null){
			Global.showTip("#message","请输入消息内容！");
			flag=false;
		}
		
		if(flag){
			//提交
			$.ajax({
 				type:"post",
 				url:"/admin/message/addMessage",
 				async:true,
 				data:{"title":title,"content":message},
 				dataType:'json',
 				success:function(data){
 					if(data.status == 'true') {
 						//以下代码在ajax返回成功后执行
 						var sucHTML="<i class='iconfont icon-jiuxu'></i>";
 						Global.submitTip(".btn-text","turnSuccess",sucHTML);
 						location.href='/admin/message/list';
 					} else {
 						//错误提示
 						var errHTML="<i class='iconfont icon-cuowu'></i>";
 						Global.submitTip(".btn-text","turnErr",errHTML);
 						location.href='/admin/message/list';
 					}
 				}
 			});
			
		}else{
			//错误提示
			var errHTML="<i class='iconfont icon-cuowu'></i>";
			Global.submitTip(".btn-text","turnErr",errHTML);
		};
	});
	
});
